﻿using System;

namespace SailHero.Soft.ESB.Communication.ClientAndServer.Communication.Messages
{
    /// <summary>
    /// This message is used to send/receive ping messages.
    /// Ping messages is used to keep connection alive between server and client.
    /// </summary>
    [Serializable]
    public sealed class PingMessage : Message
    {
        /// <summary>
        /// Message text that is being transmitted.
        /// </summary>
        public string Text { get; set; }

        private string defaultCmd = "ST=91;CN=9011;PW=123456;MN={0};Flag=1;CP=&&&&";
        ///<summary>
        /// Creates a new PingMessage object.
        ///</summary>
        public PingMessage()
        {


        }
        /// <summary>
        /// Creates a new PingMessage object with Text property.
        /// </summary>
        /// <param name="text">相应的MN号</param>
        public PingMessage(string MN)
        {
            this.Text = string.Format(defaultCmd, MN);
        }
        /// <summary>
        /// Creates a new reply PingMessage object.
        /// </summary>
        /// <param name="repliedMessageId">
        /// Replied message id if this is a reply for
        /// a message.
        /// </param>
        public PingMessage(string text, string repliedMessageId)
            : this(text)
        {
            RepliedMessageId = repliedMessageId;
        }

        /// <summary>
        /// Creates a string to represents this object.
        /// </summary>
        /// <returns>A string to represents this object</returns>
        public override string ToString()
        {
            return string.IsNullOrEmpty(RepliedMessageId)
                       ? string.Format("PingMessage [{0}]: {1}", MessageId, Text)
                       : string.Format("PingMessage [{0}] Replied To [{1}]: {2}", MessageId, RepliedMessageId, Text);
        }
    }
}
